package com.hao.demo.grpc.provider.rpc;

import io.grpc.stub.StreamObserver;
import net.devh.boot.grpc.server.service.GrpcService;
import com.hao.demo.grpc.api.*;
import org.dromara.soul.client.grpc.common.annotation.SoulGrpcClient;

@GrpcService
public class DemoServiceGrpcImpl extends DemoServiceGrpc.DemoServiceImplBase{

    @Override
    //@SoulGrpcClient(path = "/demo/get", desc = "获取")
    public void get(DemoGetRequest request, StreamObserver<DemoGetResponse> responseObserver) {
        // 创建响应对象
        DemoGetResponse.Builder builder = DemoGetResponse.newBuilder();
        builder.setId(request.getId())
                .setName("没有昵称：" + request.getId())
                .setGender(request.getId() % 2 + 1);
        // 返回响应
        responseObserver.onNext(builder.build());
        responseObserver.onCompleted();
    }

    @Override
    //@SoulGrpcClient(path = "/demo/create", desc = "创建")
    public void create(DemoCreateRequest request, StreamObserver<DemoCreateResponse> responseObserver) {
        // 创建响应对象
        DemoCreateResponse.Builder builder = DemoCreateResponse.newBuilder();
        builder.setId((int) (System.currentTimeMillis() / 1000));
        // 返回响应
        responseObserver.onNext(builder.build());
        responseObserver.onCompleted();
    }

}
